package com.atsmart.app.service;




import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.IBinder;
import android.os.PowerManager;
import android.util.Log;



public class backService extends Service {
	private PowerManager.WakeLock wakeLock = null;
	//private Notification serviceRunningNotification = null;

	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub

		return null;
	}

	LocationListener locationListener = new LocationListener() {
		public void onLocationChanged(Location l) {
		//	Log.i("tag", "OK");
		}

		public void onStatusChanged(String provider, int status, Bundle extras) {

		}

		public void onProviderEnabled(String provider) {

		}

		public void onProviderDisabled(String provider) {
		}
	};

	

	@Override
	public void onCreate() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		relesseWakeLock();
	}

	@Override
	public void onStart(Intent intent, int startid) {
		// TODO Auto-generated method stub
		//Log.i("tag", "back start");
		acquireWakeLock(); // ���� cpu

	
//		LocationManager locationManager = (LocationManager) this
//				.getSystemService(Context.LOCATION_SERVICE);
//		locationManager.requestLocationUpdates(
//				LocationManager.PASSIVE_PROVIDER, 30 * 1000, 0,
//				locationListener);
		
		
		/*
		 *  ����Ϊǰ̨����
		 */
//		serviceRunningNotification = createServiceActiveNotification();
//
//		startForeground(2322, serviceRunningNotification);

	}

	private void relesseWakeLock() {
		if (this.wakeLock == null)
			return;
		this.wakeLock.release();
		this.wakeLock = null;
	}

	private void acquireWakeLock() {
		try {
			relesseWakeLock();
			PowerManager localPowerManager = (PowerManager) getSystemService("power");
			if (localPowerManager != null) {
				String str1 = backService.class.getName();
				PowerManager.WakeLock localWakeLock = null;
//				System.out.println(Integer.valueOf(android.os.Build.VERSION.SDK));
//				if(Integer.valueOf(android.os.Build.VERSION.SDK)<14)
				 localWakeLock = localPowerManager
						.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
								| PowerManager.ACQUIRE_CAUSES_WAKEUP, str1);
//				else
//				{
//					
//					 localWakeLock = localPowerManager
//							.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK
//									| PowerManager.ACQUIRE_CAUSES_WAKEUP, str1);
//				}
				 if(localWakeLock!=null)
				this.wakeLock = localWakeLock;

			}

			if (this.wakeLock != null) {

				this.wakeLock.acquire();
			}
			return;
		} catch (Exception localException) {
		}
	}

}
